<?php

namespace App\Http\Controllers\Api\User;

use Illuminate\Http\Request;
use App\Http\Requests\Api\ApiRequest;
use App\Http\Controllers\Controller;
use App\Models\Intend;

class IntendController extends Controller
{
    public function show(ApiRequest $request)
    {
    	$where['user_id'] = $request->user_id;
   		$data         = Intend::where($where)->first();
   		$rs['data']   = $data;
   		$rs['status'] = true;
   		return response()->json($rs);
    }

    public function save(ApiRequest $request)
    {
    	$data = $request->pure();
    	$data['user_id'] = $request->user_id;
      if($request->face_score) {
        $data['face_score']    = $data['face_score']; 
      }

      if($request->age) {
        $data['age']    = ltrim(implode(',', $data['age']),',');  
      }
      
      if($request->height) {
        $data['height'] = ltrim(implode(',', $data['height']),',');  
      }
      
     
    	$flag = Intend::updateOrCreate(['user_id'=>$data['user_id']],$data);
      //dd($flag);
    	$rs['data']   = $flag;
   		$rs['status'] = true;
   		return response()->json($rs);
    }


}
